package com.baizhi.controller;

import com.baizhi.entity.News;
import com.baizhi.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/news")
public class NewsController {
    @Autowired
    private NewsService ns;
    @GetMapping
    public List<News> selectAll(){
        return ns.selectAll();
    }
    @GetMapping("/{nid}")
    public News selectOne(@PathVariable("nid") int id){
        return ns.selectOne(id);
    }
    @PostMapping
    public void  insert(@RequestBody News news){
        ns.insert(news);
    }
    @PutMapping("/{id}")
    public void update(@RequestBody News news){
        ns.update(news);
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") int id){
        ns.delete(id);
    }
}
